﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace 设计模式之禅.备忘录模式
{
    /// <summary>
    /// 发起人角色
    /// </summary>
    public class Originator
    {
        private string _state = "";
        public string GetState()
        {
            return this._state;
        }
        public void SetState(string state)
        {
            this._state = state;
        }
        public Memento CreateMemento()
        {
            return new Memento(this._state);
        }

        public void RestoreMemento(Memento memento)
        {
            this.SetState(memento.GetState());
        }
    }

    /// <summary>
    /// 备忘录角色
    /// </summary>
    public class Memento
    {
        private string _state;

        public Memento(string state)
        {
            this._state = state;
        }

        public string GetState()
        {
            return this._state;
        }

        public void SetState(string state)
        {
            this._state = state;
        }
    }

    /// <summary>
    /// 备忘录管理者角色
    /// </summary>
    public class Caretaker
    {
        private Memento memento;
        public Memento GetMemento()
        {
            return this.memento;
        }

        public void SetState(Memento memento)
        {
            this.memento = memento;
        } 
    }


}
